package com.easy.custompasswordedit;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.easy.custompasswordedit.view.CustomPassWrodEditView;
import com.easy.custompasswordedit.view.CustomPassWrodInputLayout;

public class MainActivity extends AppCompatActivity {

    private CustomPassWrodEditView mCustomPassWrodEditView;
    private CustomPassWrodInputLayout mCustomPassWrodInputLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mCustomPassWrodEditView = (CustomPassWrodEditView) findViewById(R.id.custom_pass_wrod_editview);
        mCustomPassWrodInputLayout = (CustomPassWrodInputLayout) findViewById(R.id.custom_pass_wrod_input_layout);
        mCustomPassWrodInputLayout.setCustomPassWrodListener(new CustomPassWrodInputLayout.CustomPassWrodListener() {
            @Override
            public void onClick(TextView textView) {
                String oldText = mCustomPassWrodEditView.getText().toString();
                if(oldText.length()<CustomPassWrodEditView.mPassWrodNumber){
                    String newText = oldText+textView.getText().toString();
                    mCustomPassWrodEditView.setText(newText);
                    Toast.makeText(MainActivity.this, mCustomPassWrodEditView.getText().toString(), Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void delete() {
                String oldText = mCustomPassWrodEditView.getText().toString();
                if(oldText.length()>0){
                    String newText = oldText.substring(0, oldText.length() - 1);
                    mCustomPassWrodEditView.setText(newText);
                }
            }
        });
    }
}
